//package org.geektimes.projects.userweb.config;
//
//import com.alibaba.nacos.api.config.annotation.NacosValue;
//import org.apache.ibatis.builder.xml.XMLMapperBuilder;
//import org.apache.ibatis.datasource.pooled.PooledDataSource;
//import org.apache.ibatis.io.Resources;
//import org.apache.ibatis.mapping.Environment;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.session.SqlSessionFactoryBuilder;
//import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
//import org.geektimes.projects.userweb.dao.AppUserMapper;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.sql.DataSource;
//import java.io.InputStream;
//
///**
// * @Author: jipeng
// * @Description:
// * @Date: Created in 2021/5/9 20:13
// */
//@Configuration
//@ConfigurationProperties(prefix = "my.mybatis")
//public class DBConfiguration {
//
//    @NacosValue(value = "${my.mybatis.driver:''}", autoRefreshed = true)
//    private String driver;
//    @NacosValue(value = "${my.mybatis.url:''}", autoRefreshed = true)
//    private String url;
//    @NacosValue(value = "${my.mybatis.username:''}", autoRefreshed = true)
//    private String username;
//    @NacosValue(value = "${my.mybatis.password:''}", autoRefreshed = true)
//    private String password;
//
//
//    @Bean
//    public DataSource dataSource() {
//        PooledDataSource dataSource = new PooledDataSource();
//
//        dataSource.setDriver(driver);
//        dataSource.setUrl(url);
//        dataSource.setUsername(username);
//        dataSource.setPassword(password);
//
//        return dataSource;
//    }
//
//    @Bean
//    public SqlSessionFactory getSqlSessionFactory(DataSource dataSource) {
//        Environment environment = new Environment("development", new JdbcTransactionFactory(), dataSource);
//        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
//        configuration.setEnvironment(environment);
//
//
//        configuration.setMapUnderscoreToCamelCase(true);
//
//        configuration.addMapper(AppUserMapper.class);
//
//        return new SqlSessionFactoryBuilder().build(configuration);
//    }
//
//
////    @Bean
////    public SqlSessionFactory getSqlSessionFactory() {
////        SqlSessionFactory sqlSessionFactory = null;
////        try {
////            String resource = "mybatis-config.xml";
////            InputStream inputStream = Resources.getResourceAsStream(resource);
////            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
////        } catch (Exception e) {
////            System.out.println(e.getMessage());
////        }
////        return sqlSessionFactory;
////    }
//}
